import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';

import AvatarSelector from '../../components/avatar-selector';
import { actionCreators } from '../../otherReducer/user';

import { 
    NavBar, 
    InputItem,
    TextareaItem,
    Button
} from 'antd-mobile';

class Geniusinfo extends Component {

    constructor(props) {
        super(props);
        this.state = {
            title: '',
            desc:'',
			company:'',
			money:''
        }
        this.selectAvatar = this.selectAvatar.bind(this);
    }

    handleInfoChange(key, val) {
        this.setState({
            [key]: val
        })
    }

    selectAvatar(avatar) {
        this.setState({
            avatar
        })
    }

    render() {
        const path = this.props.location.pathname;
		const redirect = this.props.redirectTo;
        return (
            <div>       
                {
                    redirect && redirect !== path ? 
                        <Redirect to={this.props.redirectTo}></Redirect> : 
                        null
                }     
                <NavBar mode="dark">求职者信息完善页面</NavBar>
                <AvatarSelector selectAvatar={this.selectAvatar}></AvatarSelector>
                <InputItem onChange={(val) => this.handleInfoChange('title', val)}>求职岗位</InputItem>
                <InputItem onChange={(val) => this.handleInfoChange('money', val)}>期望薪资</InputItem>
                <TextareaItem
                    onChange={(val)=>this.handleInfoChange('desc', val)}
					rows={3}
					autoHeight
					title='个人简介'
                ></TextareaItem>
                <Button 
                    type='primary' 
                    onClick={() => this.props.saveGeniusInfo(this.state)}
                >保存</Button>
            </div>
        )
    }
}

const mapStateToProps = (state) => ({
    redirectTo: state.getIn(['user', 'redirectTo'])
});

const mapDispatchToProps = (dispatch) => ({
    saveGeniusInfo(geniusinfo) {
        dispatch(actionCreators.updateInfo(geniusinfo));
    }
})

export default connect(mapStateToProps, mapDispatchToProps)(Geniusinfo);